package com.sunwayworld.basemodule.coredata.test.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.spring.annotation.GikamBean;

import com.sunwayworld.basemodule.coredata.test.dao.LimsTestMethodEquipmentDao;
import com.sunwayworld.basemodule.coredata.test.bean.LimsTestMethodEquipmentBean;
import com.sunwayworld.basemodule.coredata.test.service.LimsTestMethodEquipmentService;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;

import java.util.List;

@Repository
@GikamBean
public class LimsTestMethodEquipmentServiceImpl implements LimsTestMethodEquipmentService {

    @Autowired
    private LimsTestMethodEquipmentDao limsTestMethodEquipmentDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsTestMethodEquipmentDao getDao() {
        return limsTestMethodEquipmentDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        List<LimsTestMethodEquipmentBean> limsTestMethodEquipments = jsonWrapper.parse(LimsTestMethodEquipmentBean.class);
        limsTestMethodEquipments.forEach(t -> t.setId(ApplicationContextHelper.getNextIdentity()));
        getDao().insert(limsTestMethodEquipments);
        return limsTestMethodEquipments.get(0).getId();
    }

}
